#include "DebugVars.h"
#include "include/PowerLibraryEngine.h"
#include "include/ILog.h"
#include <stdio.h>

CDebugVars::CDebugVars(ISceneNodeReceiveParams):IDebugVars(ISceneNodeBasicParams),ActualPos(-1.0,1.0),ActualIndex(0),Font(NULL)
{
}

CDebugVars::~CDebugVars()
{
}

void CDebugVars::SetFont(IFont *Font)
{
	this->Font = Font;
}

void CDebugVars::Adds32(const char *Txt,s32 Value)
{
	sprintf(ValueStr,"%d",Value);
	PrepareVariable(Txt);
}

void CDebugVars::Addu32(const char *Txt,u32 Value)
{
	sprintf(ValueStr,"%u",Value);
	PrepareVariable(Txt);
}

void CDebugVars::Addbool(const char *Txt,bool Value)
{
	if (Value)
		sprintf(ValueStr,"true");
	else
		sprintf(ValueStr,"false");

	PrepareVariable(Txt);
}

void CDebugVars::PrepareVariable(const char *Txt)
{
	Temp = Txt;
	Temp += "-> ";
	Temp += ValueStr;
	GetNewIText(Temp,ActualPos);
	ActualPos.Y += 0.1f;
}

void CDebugVars::Render(IDrawableFaceManager *dfm)
{
	for (u32 i=ActualIndex;i<VectorVars.size();i++)
		VectorVars[i]->SetVisible(false);
	ActualIndex = 0;
}

void CDebugVars::GetNewIText(std::string Text,vector2dvpos &Pos)
{
	if (ActualIndex < VectorVars.size())
	{
		VectorVars[ActualIndex]->SetText(Text);
	}
	else
	{
		ITextSceneNode *NewText = SceneManager->GetSceneGenerator()->GetNewTextNode(Font,Text,
			ALIGNEMENT_X_LEFT,ALIGNEMENT_Y_UNDER);
		NewText->SetParent(this);
		NewText->SetPositionAlignedX(Pos.X);
		NewText->SetPositionAlignedY(Pos.Y);
		VectorVars.push_back(NewText);
	}

	VectorVars[ActualIndex]->SetVisible(true);
	ActualIndex++;
}
